﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HanGu.CRM
{
    public class SendMessage
    {
        public string Title { get; set; }
        public string Content { get; set; }
        public bool IsSendEmail { get; set; }
        public bool IsSendSMS { get; set; }

        /// <summary>
        /// 接收邮件地址
        /// </summary>
        public List<string> EmailTo { get; set; }
        public List<string> EmailCC { get; set; }
        /// <summary>
        /// 接收信息手机
        /// </summary>
        public List<string> SMSTo { get; set; }

        public SendMessage(bool isSendEmail=false,bool isSendSMS=false)
        {
            this.IsSendEmail = isSendEmail;
            this.IsSendSMS = isSendSMS;
        }

        public bool SendAll()
        {
            bool isSendSuccess = false;
            if (IsSendEmail)
            {
               isSendSuccess= this.SendEmail();
            }
            if (IsSendSMS)
            {
                isSendSuccess = this.SendSMS();
            }
            return isSendSuccess;
        }
        public bool SendEmail()
        {
            bool isSendSuccess = false;
            object o=new object();
            lock (o)
            {
                MailMessage mail = new MailMessage();
                mail.EmailTo = this.EmailTo;
                mail.EmailCC = this.EmailCC;
                mail.MailSubject = this.Title;
                mail.MailBody = this.Content;
                isSendSuccess=mail.SendMailSMTP();
            }
            return isSendSuccess;
        }

        public bool SendSMS()
        {
            bool isSendSuccess = false;
            SMS sms = new SMS();
            sms.SMSTo = this.SMSTo;
            sms.Message = this.Content;
            isSendSuccess = sms.Send();
            return isSendSuccess;
        }
    }
}